/**
 * 订单列表初始化
 */
var OrdersPar = {
    id: "OrdersTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
OrdersPar.initColumn = function () {
    return [
        {title:'选择项',field: 'selectItem', radio: true},
        {title: '订单ID', field: 'id', visible: true, align: 'center', valign: 'middle'},
        {title: '分销商ID', field: 'userId', visible: true, align: 'center', valign: 'middle'},
        {title: '店铺名称', field: 'shopName', visible: true, align: 'center', valign: 'middle'},
        {title: '订单编号', field: 'orderNo', visible: true, align: 'center', valign: 'middle'},
        {title: '分销订单类型', field: 'orderType', visible: true, align: 'center', valign: 'middle'},
        {title: '订单状态', field: 'orderStatus', visible: true, align: 'center', valign: 'middle'},
        {title: '预计结算日期', field: 'settlementAt', visible: true, align: 'center', valign: 'middle'},
        {title: '结算状态', field: 'settlementStatus', visible: true, align: 'center', valign: 'middle'},
        {title: '商品名称', field: 'goodsName', visible: true, align: 'center', valign: 'middle'},
        {title: '商品价格', field: 'price', visible: true, align: 'center', valign: 'middle'},
        {title: '商品封面', field: 'cover', visible: true, align: 'center', valign: 'middle',formatter: function(value,row,index){
                return '<img src="/kaptcha/'+row['cover']+'" class="img-rounded" style="width: 150px;height: 130px" >';
            }
        },
        {title: '分销商姓名', field: 'price', visible: true, align: 'center', valign: 'middle'},
        {title: '分销商等级', field: 'price', visible: true, align: 'center', valign: 'middle'},
        {title: '佣金比例', field: 'price', visible: true, align: 'center', valign: 'middle'},
        {title: '提成方式', field: 'price', visible: true, align: 'center', valign: 'middle'},
        {title: '佣金收益', field: 'price', visible: true, align: 'center', valign: 'middle'},
        {title: '积分奖励', field: 'price', visible: true, align: 'center', valign: 'middle'},
    ];
};

/**
 * 检查是否选中
 */
OrdersPar.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Feng.info("请先选中表格中的某一记录！");
        return false;
    }else{
        OrdersPar.seItem = selected[0];
        return true;
    }
};

/**
 * 查询订单列表
 */
OrdersPar.search = function () {
    //带参查询
    OrdersPar.table.refresh({query: OrdersPar.formParams()});
};
/**
 * 导出
 */
OrdersPar.export = function () {
    var ajax = new $ax(Feng.ctxPath + "/orderlist/selectListExport", function (data) {
        Feng.success("成功!");
    }, function (data) {
        Feng.error("失败!" + data.responseJSON.message + "!");
    });
    //带参导出
    ajax.set("id",$("#id").val());
    ajax.set("userId",$("#userId").val());
    ajax.set("beginTime",$("#beginTime").val());
    ajax.set("endTime",$("#endTime").val());
    ajax.start();
};

//表单参数
OrdersPar.formParams = function() {
    var queryData = {};
    queryData['id'] = $("#id").val();
    queryData['userId'] = $("#userId").val();
    queryData['beginTime'] = $("#beginTime").val();
    queryData['endTime'] = $("#endTime").val();
    return queryData;
}

//在整个页面加载的时候
$(function () {
    //初始化table-export.js文件中的变量TableExport
    // TableExport.init();

    //获取列表数据
    var defaultColunms = OrdersPar.initColumn();
    var table = new BSTable(OrdersPar.id, "/orderlist/list", defaultColunms);
    table.setPaginationType("server");
    table.setQueryParams(OrdersPar.formParams());
    OrdersPar.table = table.init();
});
